var Script = function () {

    //morris chart

    $(function () {
        // data stolen from http://howmanyleft.co.uk/vehicle/jaguar_'e'_type
        var tax_data = [];
        for (var i = 0; i < mydata.licensed1.length; i++) {
            var time = i * 5;
            var dict = {
                "period": time.toString() + " min",
                "licensed": mydata.licensed1[i],
                "sorned": mydata.sorned1[i]
            }
            tax_data.push(dict)
        }
        //var tax_data = [
        //     {"period": "5 min", "licensed": 3407, "sorned": 660},
        //     {"period": "10 min", "licensed": 3351, "sorned": 629},
        //     {"period": "15 min", "licensed": 3269, "sorned": 618}
        //     //{"period": "20 min", "licensed": 3246, "sorned": 661},
        //     //{"period": "25 min", "licensed": 3171, "sorned": 676},
        //     //{"period": "30 min", "licensed": 3155, "sorned": 681},
        //     //{"period": "35 min", "licensed": 3226, "sorned": 620},
        //     //{"period": "40 min", "licensed": 3245, "sorned": 520},
        //     //{"period": "45 min", "licensed": 3289, "sorned": 342}
        //];
        //var mydata = {{data}}
        Morris.Line({
            element: 'hero-graph',
            data: tax_data,
            xkey: 'period',
            ykeys: ['licensed', 'sorned'],
            labels: [mydata.version01, mydata.version02],
            lineColors: ['#4ECDC4', '#ed5565'],
            parseTime: false
        });
        var tax_data_ios = [];
        for (var i = 0; i < mydata_ios.licensed2.length; i++) {
            var time_ios = i * 5;
            var dict_ios = {
                "period": time_ios.toString() + " min",
                "licensed": mydata_ios.licensed2[i],
                "sorned": mydata_ios.sorned2[i]
            };
            tax_data_ios.push(dict_ios)
        }
        Morris.Line({
            element: 'hero-graph-ios',
            data: tax_data_ios,
            xkey: 'period',
            ykeys: ['licensed', 'sorned'],
            labels: [mydata_ios.version01, mydata_ios.version02],
            lineColors: ['#4ECDC4', '#ed5565'],
            parseTime: false
        });
        Morris.Donut({
            element: 'hero-donut',
            data: [
                {label: 'Jam', value: 25},
                {label: 'Frosted', value: 40},
                {label: 'Custard', value: 25},
                {label: 'Sugar', value: 10}
            ],
            colors: ['#3498db', '#2980b9', '#34495e'],
            formatter: function (y) {
                return y + "%"
            }
        });

        Morris.Area({
            element: 'hero-area',
            data: [
                {period: '2010 Q1', iphone: 2666, ipad: null, itouch: 2647},
                {period: '2010 Q2', iphone: 2778, ipad: 2294, itouch: 2441},
                {period: '2010 Q3', iphone: 4912, ipad: 1969, itouch: 2501},
                {period: '2010 Q4', iphone: 3767, ipad: 3597, itouch: 5689},
                {period: '2011 Q1', iphone: 6810, ipad: 1914, itouch: 2293},
                {period: '2011 Q2', iphone: 5670, ipad: 4293, itouch: 1881},
                {period: '2011 Q3', iphone: 4820, ipad: 3795, itouch: 1588},
                {period: '2011 Q4', iphone: 15073, ipad: 5967, itouch: 5175},
                {period: '2012 Q1', iphone: 10687, ipad: 4460, itouch: 2028},
                {period: '2012 Q2', iphone: 8432, ipad: 5713, itouch: 1791}
            ],

            xkey: 'period',
            ykeys: ['iphone', 'ipad', 'itouch'],
            labels: ['iPhone', 'iPad', 'iPod Touch'],
            hideHover: 'auto',
            lineWidth: 1,
            pointSize: 5,
            lineColors: ['#4a8bc2', '#ff6c60', '#a9d86e'],
            fillOpacity: 0.5,
            smooth: true
        });

        Morris.Bar({
            element: 'hero-bar',
            data: [
                {device: 'iPhone', geekbench: 136},
                {device: 'iPhone 3G', geekbench: 137},
                {device: 'iPhone 3GS', geekbench: 275},
                {device: 'iPhone 4', geekbench: 380},
                {device: 'iPhone 4S', geekbench: 655},
                {device: 'iPhone 5', geekbench: 1571}
            ],
            xkey: 'device',
            ykeys: ['geekbench'],
            labels: ['Geekbench'],
            barRatio: 0.4,
            xLabelAngle: 35,
            hideHover: 'auto',
            barColors: ['#ac92ec']
        });

        new Morris.Line({
            element: 'examplefirst',
            xkey: 'year',
            ykeys: ['value'],
            labels: ['Value'],
            data: [
                {year: '2008', value: 20},
                {year: '2009', value: 10},
                {year: '2010', value: 5},
                {year: '2011', value: 5},
                {year: '2012', value: 20}
            ]
        });

        $('.code-example').each(function (index, el) {
            eval($(el).text());
        });
    });

}();




